package com.asa.mvvm_aop_frame.common.exts

import android.view.View
import androidx.databinding.BindingAdapter

/**
 * create By：anderson
 * on 2022/5/1
 * desc:
 */


/**
 * @param onClickCommand Function0<Any?>
 * @param isThrottleFirst Boolean 是否设置防抖动，默认false
 */
@BindingAdapter(value = ["onClickCommand","isThrottleFirst"], requireAll = false)
fun View.onClickCommand(onClickCommand : ()->Any,isThrottleFirst:Boolean){
    val minTime = 500L
    var lastTime =0L
    val tmpTime = System.currentTimeMillis()
    if (isThrottleFirst){
        onClickCommand()
    } else {
        if (tmpTime - lastTime > minTime){
            onClickCommand()
            lastTime = tmpTime
        }
    }

}